package com.cavy.platform.server.domain;

import com.cavy.platform.server.domain.job.JobDispatcher;
import com.cavy.platform.server.domain.job.LeastJobSelector;
import com.cavy.platform.server.domain.job.MostResourceJobSelector;
import com.cavy.platform.server.domain.job.RandomJobSelector;

import java.util.HashSet;
import java.util.Set;

/**
 * @author 唐旭
 * @Date 2018/7/25
 */
public class AgentSelectorFactory {
    private static Set<JobDispatcher> DISPATCHER_SET = new HashSet<>();

    static {
        DISPATCHER_SET.add(new RandomJobSelector());
        DISPATCHER_SET.add(new LeastJobSelector());
        DISPATCHER_SET.add(new MostResourceJobSelector());
    }

    public static JobDispatcher getSelector(SchedulingStrategy schedulingStrategy) {
        for (JobDispatcher bean : DISPATCHER_SET) {
            if (bean.support(schedulingStrategy)) {
                return bean;
            }
        }
        throw new RuntimeException("未找到Job选择器");
    }
}
